package org.ueg.dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;




public class Dao {
	private static Configuration configuration = null;
	private static ServiceRegistry serviceRegistry = null;
	private static SessionFactory sessionFactory = null;

	
	public Dao(){

		if (configuration == null){
			configuration = new Configuration();
			configuration.configure();			
		}
		if (serviceRegistry == null){
			serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
		}
        if (sessionFactory == null) {
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        }		
	}

	public Session getSession(){
		return sessionFactory.openSession();
	}
	
	


}
